<template>
	<view>
		<view class="tabBox">
			<view>
				<text v-for="item in tagList" :key="item" @click="active=item" :class="active==item?'choose':''">
					{{item}}
				</text>
			</view>
			<view>
				<u-icon name='list' size='40rpx' @click='show=true' />
			</view>
		</view>
		<u-popup :show="show" :round="10" @close="show=false">
			<view class="popupTitle">
				<u-icon name='close' color='#fff' />
				<view>
					筛选条件
				</view>
				<u-icon name='close' @click='show=false' />
			</view>
			<view class="viewWidth">
				<u--form labelWidth='100%' labelPosition="top" :model="form" ref="uForm">
					<u-form-item v-if="!activeType" label="关键字:" borderBottom>
						<u--input v-model="form.keywords" placeholder="请输入关键字" />
					</u-form-item>
					<u-form-item v-if="activeType" label="状态:" borderBottom>
						<u-checkbox-group v-model="form.status">
							<u-checkbox :customStyle="{marginRight: '8px'}" v-for="(item, index) in statusList"
								:key="index" :label="item.name" :name="item.id">
							</u-checkbox>
						</u-checkbox-group>
					</u-form-item>
					<u-form-item v-if="activeType" label="工艺流程:" borderBottom>
						<view class="inputBox" @click="processShow=true">
							<view>
								{{form.process.name?form.process.name:'请选择工艺流程'}}
							</view>
							<view @click.stop='()=>{}'>
								<u-icon size='28rpx' color='#bbb' name='close-circle' v-if="form.process.id"
									@click.stop='form.process={name:"",id:""}' />
							</view>
						</view>
					</u-form-item>
					<u-form-item v-if="activeType&&customerType" label="工地:" borderBottom>
						<view class="inputBox" @click="customerShow=true">
							<view>
								{{form.customer.name?form.customer.name:'请选择工地'}}
							</view>
							<view @click.stop='()=>{}'>
								<u-icon size='28rpx' color='#bbb' name='close-circle' v-if="form.customer.id"
									@click='form.customer={name:"",id:""}' />
							</view>
						</view>
					</u-form-item>
					<u-form-item v-if="activeType&&authorizerType" label="审核人:" borderBottom>
						<view class="inputBox" @click="authorizerShow=true">
							<view>
								{{form.authorizer.name?form.authorizer.name:'请选择审核人'}}
							</view>
							<view @click.stop='()=>{}'>
								<u-icon size='28rpx' color='#bbb' name='close-circle' v-if="form.authorizer.id"
									@click='form.authorizer={name:"",id:""}' />
							</view>
						</view>
					</u-form-item>
					<u-form-item v-if="activeType&&administratorType" label="发布人:" borderBottom>
						<view class="inputBox" @click="administratorShow=true">
							<view>
								{{form.administrator.name?form.administrator.name:'请选择发布人'}}
							</view>
							<view @click.stop='()=>{}'>
								<u-icon size='28rpx' color='#bbb' name='close-circle' v-if="form.administrator.id"
									@click='form.administrator={name:"",id:""}' />
							</view>
						</view>
					</u-form-item>
				</u--form>
			</view>
			<view class="viewWidth">
				<u-button @click='reload'>
					确认
				</u-button>
			</view>
		</u-popup>
		<view>
			<u-picker keyName='title' :show="processShow" :columns="processList" @confirm='processConfirm'
				@cancel='processShow=false'></u-picker>
			<selectCustomer v-if="activeType&&customerType" :show='customerShow' @close='customerShow=false'
				@selectCustomer='selectCustomer' />
			<selectAuthorizer v-if="activeType&&authorizerType" :show='authorizerShow' @close='authorizerShow=false'
				@selectAuthorizer='selectAuthorizer' />
			<selectAdministrator v-if="activeType&&administratorType" :show='administratorShow'
				@close='administratorShow=false' @selectAdministrator='selectAdministrator' />
		</view>
	</view>
</template>

<script>
	import selectCustomer from '@/components_company/selectCustomer';
	import selectAuthorizer from '@/components_company/selectAuthorizer';
	import selectAdministrator from '@/components_company/selectAdministrator';
	export default {
		components: {
			selectCustomer,
			selectAuthorizer,
			selectAdministrator
		},
		name: "filter",
		data() {
			return {
				tagList: ['正常', '排序'],
				active: '正常',
				show: false,
				form: {
					keywords: '',
					status: [],
					process: {
						name: '',
						id: ''
					},
					customer: {
						name: '',
						id: ''
					},
					authorizer: {
						name: '',
						id: ''
					},
					administrator: {
						name: '',
						id: ''
					}
				},
				activeType: false,
				authorizerType: false,
				customerType: false,
				administratorType: false,
				statusList: [{
						name: '待审核',
						id: -1
					},
					{
						name: '驳回',
						id: 1
					},
					{
						name: '通过',
						id: 2
					}
				],
				processShow: false,
				processList: [
					[]
				],
				customerShow: false,
				authorizerShow: false,
				administratorShow: false
			};
		},
		mounted() {
			if(!uni.getStorageSync('token')) return
			let pages = getCurrentPages(); // 获取栈实例
			console.log(pages[pages.length - 1].route)
			const route = pages[pages.length - 1].route
			if (route == 'authorizer/list') {
				this.activeType = true
				this.customerType = true
				this.administratorType = true
				this.getProcessList()
			} else if (route == 'My/active') {
				this.activeType = true
				this.customerType = true
				this.authorizerType = true
				this.getProcessList()
			} else if (route == 'shop/index') {
				this.administratorType = true
				this.activeType = true
				this.customerType = true
				this.authorizerType = true
				this.getProcessList()
			}
		},
		methods: {
			reload() {
				this.show = false
				this.$emit('reload', this.form)
			},
			processConfirm(e) {
				this.form.process.name = e.value[0].title
				this.form.process.id = e.value[0].id
				this.processShow = false
			},
			getProcessList() {
				this.$api_company.Process.List().then(res => {
					this.processList = [res.data.process]
				})
			},
			selectCustomer(item) {
				this.form.customer.name = item.remark_name
				this.form.customer.id = item.id
				this.customerShow = false
			},
			selectAuthorizer(item) {
				this.form.authorizer.name = item.members.nick_name
				this.form.authorizer.id = item.user_id
				this.authorizerShow = false
			},
			selectAdministrator(item) {
				this.form.administrator.name = item.nick_name
				this.form.administrator.id = item.id
				this.administratorShow = false
			}
		}
	}
</script>

<style lang="scss" scoped>
	.tabBox {
		padding: 20rpx 0 0;
		display: flex;
		flex-direction: row;
		justify-content: space-between;

		>view {
			display: flex;
			flex-direction: row;
		}

		text {
			padding: 10rpx 20rpx;
			border-radius: 8rpx;
			background-color: #F2F2F2;
			font-size: 26rpx;
			margin-right: 20rpx;
		}

		.choose {
			color: #fff;
			background-color: rgb(57, 117, 198);
		}
	}

	.viewWidth {
		width: 92vw;
		margin: 10rpx auto;
	}
</style>